// YaP IRC - IRC Channels List.
//Copyright (C) 2006  Pierre-Alain DAVID

//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either
//version 2.1 of the License, or (at your option) any later version.

//This library is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//Lesser General Public License for more details.

//You should have received a copy of the GNU Lesser General Public
//License along with this library; if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

using System;
using System.Windows.Forms;
using YaP.Library;

namespace YaP.Forms
{
    public partial class ChanListForm : Form
    {
        public bool InUse;

        public ChanListForm()
        {
            InitializeComponent();
        }

        private void chnList_Load(object sender, EventArgs e)
        {
        }

        public void AddChan(string name, string count, string topic)
        {
            ChannelListItem toadd = new ChannelListItem(name, count, topic);
            listBox1.Invoke((MethodInvoker) delegate { listBox1.Items.Add(toadd); });
        }

        private void chnList_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (InUse)
            {
                e.Cancel = true;
            }
            else
            {
                ((MainForm) MdiParent).KillChannelList(this);
            }
        }

        private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            string[] args = new string[2];
            args[0] = ((ChannelListItem) listBox1.SelectedItem).Channel;
            ((MainForm) MdiParent).DoCmd("JOIN", args);
        }

        private void nameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            listBox1.Sorted = true;
            //var x = from c in listBox1.Items orderby ((ChannelListItem)c).Channel select c;
            //listBox1.Items.Clear();
            //foreach (ChannelStyle ch in x)
            //{
            //    listBox1.Items.Add(ch);
            //}
        }

        private void chnList_Activated(object sender, EventArgs e)
        {
        }
    }
}